import { defineSource } from '../source';
import { ProcessedItem } from '../types'
import { myFetch } from "../utils/fetch"
import * as cheerio from "cheerio"
import logger from '../../framework/config/logger';

/**
 * 排行榜 
 */
export default defineSource({
    chongbuluo: async (): Promise<ProcessedItem[]> => {
        const baseUrl = "https://www.chongbuluo.com/"
        const html: string = await myFetch(`${baseUrl}forum.php?mod=guide&view=hot`)
        const $ = cheerio.load(html)
        const news: ProcessedItem[] = []
        $(".bmw table tr").each((_, elem) => {
            const xst = $(elem).find(".common .xst").text()
            const url = $(elem).find(".common a").attr("href")
            const hot = $(elem).find(".num em").text()
            news.push({
                id: baseUrl + url,
                title: xst,
                url: baseUrl + url,
                extra: {
                    hot: hot,
                },
            })
        })
        return news
    }
});
